using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using Data.FileManager;
using System.Collections;
using System.IO;
namespace WindowsApplication2.Gui
{
    public partial class SaveFile : UserControl
    {
        private FileHandler fh;
        private ArrayList savedItems;
        string type;
        public SaveFile()
        {
            InitializeComponent();
        }
        public void InitilizeData(ArrayList savedItems, string type)
        {
            fh = FileHandler.Instance;
            this.savedItems = savedItems;
            this.type = type;
        }

        private void SaveFile_Load(object sender, EventArgs e)
        {
            this.txt_FileName.SelectAll();
            this.txt_FileName.Focus();
            this.rbtn_Save.Enabled = false;
            this.rlbl_Results.Visible = false;
        }

        private void txt_FileName_TextChanged(object sender, EventArgs e)
         {
            if (this.txt_FileName.Text.Trim() == "")
                this.rbtn_Save.Enabled = false;
            else
                this.rbtn_Save.Enabled = true;
        }

        private void rbtn_Cancel_Click(object sender, EventArgs e)
        {
            this.Visible = false;
        }

        private void rbtn_Save_Click(object sender, EventArgs e)
        {
            StreamWriter sWriter = fh.getFileToWrite(this.type ,FileHandler.WorkingDirectory + this.txt_FileName.Text + ".dat");
            foreach (object obj in this.savedItems)
                sWriter.WriteLine(obj);
            sWriter.Flush();
            sWriter.Close();
            this.rlbl_Results.Visible = true;
            System.Threading.Thread.Sleep(2000);
            this.Visible = false;
        }
    }

}
